package com.ellricky.baselib.ui;

import android.content.Intent;
import android.widget.TextView;

import androidx.viewpager.widget.ViewPager;

import com.andr.common.ui.activity.BaseToolBarActivity;
import com.ellricky.baselib.R;
import com.ellricky.baselib.adapter.ImageAdapter;
import com.ellricky.baselib.adapter.SimpleImageAdapter;
import com.ellricky.baselib.widget.ImageViewPager;

import java.util.List;
import java.util.Locale;

/**
 * Created by april on 16/11/10.
 */

public class ImageGalleryActivity extends BaseToolBarActivity {
    private ImageViewPager viewPager;
    private TextView tvNum;

    private List<String> urlList;
    private ImageAdapter adapter;
    private boolean canZoom;

    @Override
    public void initUIView() {
        super.initUIView();
        mTvTitle.setText("图片查看");
        viewPager = findViewById(R.id.viewpager);
        tvNum = findViewById(R.id.tv_num);

        Intent intent = getIntent();
        urlList = intent.getStringArrayListExtra("urlList");
        canZoom = intent.getBooleanExtra("canZoom", true);
        int position = intent.getIntExtra("curIndex", 0);
        adapter = new ImageAdapter(getSupportFragmentManager(), urlList, canZoom);
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(position);

        updateNumText(position);

        viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                updateNumText(position);
            }
        });
    }

    @Override
    public int getContentLayout() {
        return R.layout.base_image_activity_galley;
    }

    private void updateNumText(int curIndex) {
        tvNum.setText(String.format(Locale.CHINA, "%d/%d", curIndex + 1, urlList.size()));
    }
}
